# coding=utf-8
# -*- coding: UTF-8 -*-
#
# This file is part of the kernelstudio package.
#
# (c) 2014-2025 zlin <admin@kernelstudio.com>
#
# For the full copyright and license information, please view the LICENSE file
# that was distributed with this source code.

import typing as t

from flask import render_template, Response
from jinja2 import Template


def render(template: str | Template | list[str | Template], status: t.Optional[int] = 200, **context: t.Any):
    content = render_template(template, **context)
    response = Response(content, status=status, mimetype='text/html', content_type='text/html')
    return response


def render_error(status: t.Optional[int] = 500, code: t.Optional[str] = "500", message: t.Optional[str] = "未知错误"):
    return render("error.html", code=code, status=status, message=message)
